#include <iostream>
#include <cmath>
using namespace std;
int main3()
{
	int mes[100100] = { 0,0 };
	int N, M;
	cin >> N;
	for (int i = 1; i <= N; i++)
	{
		cin >> M;
		if (M == N)
		{
			int j = M;
			if (mes[j] == 0) mes[j] = mes[i] + 1;
			else mes[j] = min(mes[i] + 1, mes[j]);
			cout << mes[N];
			return 0;
		}
		for (int j = i + 1; j <= M; j++)
		{
			if (mes[j] == 0) mes[j] = mes[i] + 1;
			else mes[j] = min(mes[i] + 1, mes[j]);
		}
	}
	return 0;
}